//
// main.c
//

#include <video_select_server.h>
#include <video_server_common.h>
#include <video_multi_player.h>
#include <stdio.h>

struct video_multi_player_t video_mp;

int add_client_player(struct video_client_bind_t *bind)
{
	return add_video_player(&video_mp, bind);
}

int remove_client_player(struct video_client_bind_t *bind)
{
	return remove_video_player(&video_mp, bind);
}

int main() {
	struct video_server_t *my_server;
	struct video_player_events_t player_events;

	// init the video multi player
	video_multi_player(&video_mp);

	// init the tcp server & set binding delegates
	my_server = (struct video_server_t*) malloc(sizeof(struct video_server_t));
	player_events.on_client_connected = &add_client_player;
	player_events.on_client_disconnected = &remove_client_player;	
	video_server(my_server, &player_events);

	if (!my_server) {
		perror("could not init the video server");
		exit(-1);
	}
	printf("server init!\n");

	if (video_server_start(my_server) < 0) {
		perror("could not start the video server");
		exit(-2);
	}
	printf("server running! (press any key to stop)\n");
	getchar();

	if (video_server_close(my_server) < 0) {
		perror("failed stopping the video server");
		exit(-3);
	}
	printf("server stopped! (press any key to quit)\n");
	getchar();
	
	return 0;
}
